# Look for files of interest
files = list.files(path = "tmp", pattern = "*.json", full.names = TRUE)
stopifnot(length(files) > 0)
print(files)## [1] "tmp/BCH.json" "tmp/BCHABC.json" "tmp/BTC.json"
## [4] "tmp/EOS.json" "tmp/ETC.json" "tmp/ETH.json"
## [7] "tmp/LTC.json" "tmp/REP.json" "tmp/XLM.json"
## [10] "tmp/XRP.json" "tmp/ZRX.json"
# Get the times from the first coin
raw = fromJSON(file = files[1])
timestamp = c(); for (observation in raw$Data) timestamp = c(timestamp, observation$time)
# Fix time offset (Epoch to friendly units)
timestamp = timestamp - timestamp[1]
timestamp = timestamp / 3600
prices <- cbind(timestamp)
# Add a new column for each coin
for (f in files) {
raw = fromJSON(file = f)
p = c(); for (observation in raw$Data) p = c(p, observation$close)
prices <- cbind(prices, usd = p)
}# X-axis is time
x <- prices[,1]
# Plot prices on the Y-axis
for (i in 3:12) {
y <- prices[,i]
relation <- lm(y ~ x)
par(bg = "gray94")
plot(x, y, col = "orange", main = files[i - 1],
abline(relation, col="red", lty = 10), xlab = "hours", ylab = "USD")
}